package com.example.permissionservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.permissionservice.entity.UserRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserRoleMapper extends BaseMapper<UserRole> {
    @Select("SELECT role_code FROM roles r " +
            "INNER JOIN user_roles u ON r.role_id = u.role_id " +
            "WHERE u.user_id = #{userId}")
    String selectUserRoleByUserId(@Param("userId") Long userId);

    @Select("SELECT user_id FROM user_roles WHERE role_id = 2")
    List<Long> selectUsers();

    @Update("UPDATE user_roles SET role_id = 3 WHERE user_id = #{userId}")
    void upgradeByUserId(@Param("userId") Long userId);

    @Update("UPDATE user_roles SET role_id = 2 WHERE user_id = #{userId}")
    void downgradeByUserId(@Param("userId") Long userId);



}
